// 展示商品信息
function show(dataString) {
    const jsonStringArray = JSON.parse(dataString);
    const data = jsonStringArray.map(item => JSON.parse(item));
    const contentElement = document.querySelector('.banner2-box');
    const fragment = document.createDocumentFragment();
    contentElement.innerHTML = "";
    for (let i = 0; i < data.length; i++) {
        const htmlContent = `
        <a href="../info.html" class="banner2-item" onclick="saveData(${data[i].id})">
            <img src="${data[i].image}" alt="商品图片" class="img">
            <p class="title">${data[i].name}</p>
            <div>
                <span class="price1">￥</span>
                <span class="price2">${data[i].price}元</span>
                <button class="buy">立即购买</button>
            </div>
        </a>
    `;
        const tempElement = document.createElement('div');
        tempElement.innerHTML = htmlContent;
        fragment.appendChild(tempElement.firstElementChild);
    }
    contentElement.appendChild(fragment);
}

// 保存商品id
function saveData(id) {
    sessionStorage.setItem('id',id);
}

